package com.farm.quartz.controller;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.farm.common.core.controller.BaseController;
import com.farm.common.core.domain.AjaxResult;
import com.farm.quartz.Dao.haohaoDao;
import com.farm.quartz.Dao.wuLawPerDao;
import com.farm.quartz.model.haohao;
import com.farm.quartz.model.wuLawPer;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.*;

@RestController
@RequestMapping("enterprise/lawer")
public class lawPersonController extends BaseController {
    @Resource
    wuLawPerDao wulawperdao;
    @Resource
    wuPageController wupage;

//    @GetMapping("list")
//    public AjaxResult ALL(){
//        ArrayList<wuLawPer> a = wulawperdao.findAll();
////        Iterator<wuLawPer> iterator = a.iterator();
////        while(iterator.hasNext()) {//判断当前“指针”下面是否还有元素
////            System.out.println(iterator.next());//如果指针下面有元素，则移动指针并获取相应位置的元素
////        }
//        Map<String,String> map = new HashMap<>();
////        map.put("name",a.getName());
////        JSONObject.toJSONString(map)
//        return AjaxResult.success(a);
//    }

    @PostMapping("selectlawer")
    public AjaxResult search(@RequestBody wuLawPer wuLawPer){

        return AjaxResult.success(wulawperdao.getById(wuLawPer.getId()));
//        return
//        Map<String,Object> map = new HashMap<>();
//        map.put("id",a.getId());
//        map.put("sex",a.getSex());
//        map.put("name",a.getName());
//        map.put("age",a.getAge());
//       return AjaxResult.success(map);
    }

    @PostMapping("deletelawer")
    @ResponseBody
    public AjaxResult deleteById(@RequestBody String json)
    {
        int id = JSONObject.parseObject(json).getIntValue("id");
        System.out.println("=================================================================");
//        wuLawPer wuLawPer = new wuLawPer();
//        wuLawPer.setAge("1");
//        wuLawPer.setName("2");
//        wuLawPer.setSex("3");
//        wuLawPer.setId(10);
//        wulawperdao.save(wuLawPer);
            wulawperdao.delete(id);
        return wupage.ALL1(10,10);

    }
    @PostMapping("addlawer")
    @ResponseBody
    public AjaxResult addById(@RequestBody wuLawPer wuLawPer)
    {
       return AjaxResult.success("新增成功",wulawperdao.save(wuLawPer));


    }


    @PostMapping("udpatelawer")
    @ResponseBody
    public AjaxResult updateById(@RequestBody String json)
    {

        String age = JSONObject.parseObject(json).getString("age");
        String sex = JSONObject.parseObject(json).getString("sex");
        String name = JSONObject.parseObject(json).getString("name");
        int id = JSONObject.parseObject(json).getIntValue("id");
        wulawperdao.update(age,sex,name,id);
        return wupage.ALL1(10,10);

    }



}
